package Stack;

import org.apache.groovy.json.internal.JsonStringDecoder;

import java.util.Stack;

//获取栈中最小值
class MinStack {
    Stack<Integer> stack=new Stack<>();
    Stack<Integer> MinStack=new Stack<>();

    public MinStack(){
        stack=new Stack<>();
        MinStack=new Stack<>();
    }

    public void push(int val){
        stack.push(val);
        if(MinStack.isEmpty()){
            MinStack.push(val);
        }else{
            int peekMinVal=MinStack.peek();
            if(val<=peekMinVal){
                MinStack.push(val);
            }
        }
    }

    public void pop(){
        int val=stack.pop();
        if(val==MinStack.peek()){
            MinStack.pop();
        }
    }

    public int top(){
        return stack.peek();
    }

    public int getMinStack(){
        return MinStack.peek();
    }

}
